package pl.iachoo.ctl.tabory.dao.hibernate.services;

import org.apache.log4j.Logger;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

import pl.iachoo.ctl.tabory.dao.api.services.ICompositionService;
import pl.iachoo.ctl.tabory.dao.api.services.ITripService;
import pl.iachoo.ctl.tabory.dao.api.services.IUserRoleService;
import pl.iachoo.ctl.tabory.dao.api.services.IUserService;
import pl.iachoo.ctl.tabory.dao.api.services.IVagonService;
import pl.iachoo.ctl.tabory.dao.hibernate.services.impl.CompositionDaoServiceImpl;
import pl.iachoo.ctl.tabory.dao.hibernate.services.impl.TripDaoServiceImpl;
import pl.iachoo.ctl.tabory.dao.hibernate.services.impl.UserDaoServiceImpl;
import pl.iachoo.ctl.tabory.dao.hibernate.services.impl.UserRoleDaoServiceImpl;
import pl.iachoo.ctl.tabory.dao.hibernate.services.impl.VagonDaoServiceImpl;

public class ServiceManager {

	private final static Logger logger = Logger.getLogger(ServiceManager.class);

	protected static SessionFactory sessionFactory;

	static {
		logger.info("Static initialization of ServiceManager");
		try {
			logger.info("Building SessionFactory...");
			sessionFactory = new Configuration().configure()
					.buildSessionFactory();
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
		}
	}

	public static IUserRoleService getUserRoleService() {
		logger.info("Retriving UserRoleDaoServiceImpl...");
		IUserRoleService userRoleService = new UserRoleDaoServiceImpl(
				sessionFactory);
		return userRoleService;
	}

	public static IUserService getUserService() {
		logger.info("Retriving UserDaoServiceImpl...");
		IUserService userService = new UserDaoServiceImpl(sessionFactory);
		return userService;
	}

	public static IVagonService getVagonService() {
		logger.info("Retriving VagonDaoServiceImpl...");
		IVagonService vagonService = new VagonDaoServiceImpl(sessionFactory);
		return vagonService;
	}

	public static ICompositionService getCompositionService() {
		logger.info("Retriving CompositionDaoServiceImpl...");
		ICompositionService compositionService = new CompositionDaoServiceImpl(
				sessionFactory);
		return compositionService;
	}

	public static ITripService getTripService() {
		logger.info("Retriving TripDaoServiceImpl...");
		ITripService tripService = new TripDaoServiceImpl(sessionFactory);
		return tripService;
	}
}
